﻿using System;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

namespace sdamarketing
{
    public partial class viewPosts : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            string sqlPrijateli = "SELECT idUserPrijatel FROM Prijatel Where (idUser = '"+Session["idUser"].ToString()+"')";
            SqlCommand cmd2 = new SqlCommand(sqlPrijateli,ConnectionMenager.GetConnection());
            SqlDataReader dataReaderPrijateli = cmd2.ExecuteReader();

            string SQL_IDPrijateli="";
            if (dataReaderPrijateli.HasRows)
            {
                while (dataReaderPrijateli.Read())
                {
                    //int pom = dataReaderPrijateli.GetInt32(0);
                    SQL_IDPrijateli += " OR (Postovi.idUser='" + dataReaderPrijateli.GetInt32(0).ToString() + "')";
                }
            }
            string sSQL = "SELECT Postovi.Status, Postovi.VideoURL,Users.username,"
                                + "Postovi.VideoOpis FROM  Postovi INNER JOIN Users ON Postovi.idUser = Users.idUser"
                                + " WHERE (Postovi.idUser = '" + Session["idUser"].ToString() + "')";
            sSQL = sSQL + SQL_IDPrijateli;

            SqlCommand cmd = new SqlCommand(sSQL,ConnectionMenager.GetConnection());  
            SqlDataReader dataReader = cmd.ExecuteReader();
   
            rep1.DataSource = dataReader;
            rep1.DataBind();
        }

        protected void rep1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
          /*  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRow row = e.Item.DataItem as DataRow;
                Literal litname = e.Item.FindControl("litname") as Literal;
                
                litname.Text = row["Status"].ToString();
                
                Label LabelShowYouTubeVideo = e.Item.FindControl("LabelShowYouTubeVideo") as Label;
                string url = row["VideoURL"].ToString();
                string YouTubeID = url.Remove(0, 31);
                LabelShowYouTubeVideo.Text = "<object width='425' height='355'><param name='movie' value='http://www.youtube.com/v/" + YouTubeID + "'></param><param name='wmode' value='transparent'></param><embed src='http://www.youtube.com/v/" + YouTubeID + "' type='application/x-shockwave-flash' wmode='transparent' width='425' height='355'></embed></object>"; ;

                Label LabelOpisVideo = e.Item.FindControl("LabelOpisVideo") as Label;
                LabelOpisVideo.Text = row["VideoOpis"].ToString();
           */
            }
        } 
    }
